const conn = require('../../libs/DB/Conn');

module.exports = async function (params) {
//项目中统一使用驼峰标识 数据库中的字段为使用字母小写_，因此需要进行字段名装换，前期目的是为了避免写SQL时使用 SELECT * FROM
    let querySql = `SELECT
                        uf.user_id AS userId,
                        uf.login_name AS loginName,
                        uf.user_name AS userName,
                        uf.mobile,
                        uf.group_id AS groupId,
                        ug.group_name AS groupName
                    FROM
                        user_file uf
                    INNER JOIN user_group ug ON ug.group_id = uf.group_id AND ug.is_manager != 1
                    WHERE
                        uf.delete_sign = 1
                    AND uf.domain_id = ${params.userDomainId}
                    ${params.groupId ? 'AND uf.group_id = '+params.groupId : ''} 
                    ${params.searchText ? 'AND uf.user_name LIKE "%'+params.searchText + '%"' : ''}    
                    ORDER BY uf.group_id ASC`;
    let result = await conn(querySql);

    return {success: true, data: result}
};